<template>
  <div>
    <van-nav-bar :title="title" :fixed="true" />

    <div class="container">
      <router-view @toparent="getTitle" v-if="isRouterAlive"></router-view>
    </div>

    <van-popup v-model="show" position="bottom" :style="{ height: '40%'}">
      <div class="zhier">
        <h4 style="color: white;">杉果游戏</h4>
        <span>
          <van-icon class="close" name="cross" @click="close" />
        </span>
      </div>
      <div class="btn">
        <van-button class="van-button" plain hairline type="default" color="#000" to="/login">登录</van-button>
        <van-button class="van-button" plain hairline color="#000" type="default" to="/register">注册</van-button>
      </div>
    </van-popup>

    <div class="footer">

      <van-tabbar route :fixed="true">
        <van-tabbar-item icon="wap-home" to="/home" replace  >首页</van-tabbar-item>
        <van-tabbar-item icon="apps-o" to="/gamelist" replace >游戏</van-tabbar-item>
        <van-tabbar-item icon="bag-o" to="/cart" @click="tomain" replace>购物车</van-tabbar-item>
        <van-tabbar-item icon="manager-o" to="/main" @click="tomain">个人中心</van-tabbar-item>
      </van-tabbar>
    </div>
  </div>
</template>

<script>
export default {
  name: "Index",
  provide() {
    return {
      reload: this.reload
    };
  },
  data() {
    return {
      value: "",
      title: "首页",
      show: false,
      path: "",
      isRouterAlive: true
    };
  },
  mounted() {
    this.$emit("toparent", this.title);
  },
  methods: {
    reload() {
      this.isRouterAlive = false;
      this.$nextTick(function() {
        this.isRouterAlive = true;
      });
    },
    getTitle(msg) {
      this.title = msg;
    },
    tomain() {
      let user = localStorage.getItem('access-user');
      if (!user) {
        this.show = true;
      } else {
        this.$router.push("/main");
      }
    },
    close() {
      this.show = false;
    }
  }
};
</script>

<style scoped>
.footer span {
  display: block;
}
.container {
  margin: 46px 0 50px;
}
.zhier {
  padding: 5vw;
}
.zhier h4 {
  margin: 0;
  width: 30vw;
  font-size: 16px;
  float: left;
}
.zhier .close {
  float: right;
}
.btn {
  margin-top: 50px;
  text-align: center;
}
.btn .van-button {
  width: 150px;
}
.van-nav-bar--fixed {
    background-color: #706E6E ;
}
.van-ellipsis {
    color: white;
}
</style>
